1. Field of the Invention
The present invention is related to a method for detecting a code error, and more particularly, to a method that is used to detect whether there is only a bit of error that exists in the accessed data.
2. Description of Related Art
Nowadays, the propagation of information is very fast. In the past, people usually used magnetic disks, such as floppy disks, to carry data. However, the storage capacity of magnetic disks is quite limited. Hence, when one needs to carry a great quantity of data, he has no choice but to use a hard disk or optical disk to carry the data. That is very inconvenient. With the rapid progress of computer science in recent years, in order to solve this problem, computer companies employed memories, such as flash memories, to develop a variety of memory cards or portable disks with various storage capacities. These memory cards or portable disks are compatible to portable electronic products such as notebook computers, personal digital assistants (PDA), cellular phones, digital cameras and the like. They have large storage capacity and can be used to store altogether MP3 files, picture files and important briefing files needed. Since this kind of memory cards or portable disks can be accessed with a high data transfer rate and easily carried, they are very convenient and practical. Hence, they are usually used in schools, offices, business travels and so forth at present. After this kind of storage media was introduced into the market, people don't need to use magnetic disks or hard disks to carry their data any more. Therefore, the inconvenience for carrying data in the past is removed completely.
Presently, in order to avoid the data transfer error of memories due to noise interference, the portable electronic apparatuses, such as card-reading machines, notebook computers, PDAs, cellular phones and digital cameras, usually have error-checking circuits. When the portable electronic apparatus needs to transfer data to a memory, it first uses the error-checking circuit to generate an error correction code (ECC) corresponding to the data and then store the data and the error correction code to the memory. On the contrary, when portable electronic apparatus needs to access the data stored in the memory, it first reads out the data together with the corresponding error correction code and then uses the error-checking circuit to generate another error correction code according to the read data. After that, the portable electronic apparatus compares the error correction code obtained from the memory with the new generated one to check whether the accessed data are correct or not. If these two error correction codes are exactly the same, it means the accessed data are correct completely. The steps of the conventional method are described in detail as below.
When the portable electronic apparatus compares the two error correction codes, it generates an error comparison code. The portable electronic apparatus can use this error comparison code to determine whether the accessed data are correct or not. If the accessed data are error, the portable electronic apparatus can also use this error comparison code to find the error type and set the Status bit accordingly. The portable electronic apparatus can use the Status bit to determine whether the error data can be corrected or not. If every bit of the error comparison code is “0”, it means the two error correction codes are exactly the same and the accessed data are correct completely. If one bit of the error comparison code is “1”, it means that there is an error bit existing in the accessed data. This error type is called code error and its corresponding data can be corrected.
In order to clarify the operation of the portable electronic apparatus about the error comparison code, a four-bit error comparison code is used as an example. First, for a four-bit error comparison code, there are four types of code errors: (0001), (0010), (0100) and (1000). Suppose that an apparatus, called the first apparatus, stores its ready data together with the corresponding error correction code (0101), called the first error correction code, into a memory. After that, another apparatus, called the second apparatus, reads out the data together with the corresponding error correction code (0101) and then generates another error correction code (0001), called the second error correction code, according to the data. Then, the second apparatus compares the first and second error correction codes so as to generate a corresponding error comparison code (0100). This error comparison code is the same as one type of the code errors mentioned above. It means that the data accessed from the memory have a one-bit error and can be corrected.
Most of the conventional apparatuses that can be used to access memories use electric circuits to perform the pattern comparison method to determine whether the error comparison code is the same as one type of the code errors or not. The so-called pattern comparison method is to provide all types of the code errors in advance and then compare the error comparison code with these code errors one by one. For example, for comparison of a four-bit error comparison code, the code errors including (0001), (0010), (0100) and (1000) should be provided in advance. Then, the four-bit error comparison code is compared with these code errors one by one to determine whether the error comparison code is the same as one of the code errors or not.
Although the pattern comparison method is a simple and direct method, it still has some problems. For example, if the code length of the error comparison code increases, i.e. the number of bits that it includes increases, more patterns of the code errors need to be provided in this method. At the same time, the size of the comparison circuit needed also becomes larger. It makes the complexity of the comparison circuit and the number of the electric components increased. Besides, the time consumed for comparison with the code errors will also become longer. In practice, the comparison circuit used for a N-bit error comparison code must have N comparators and N−1 OR gates.
Therefore, how to provide a method for determining the code error type of accessed data to remove the drawbacks of the prior art has been desired for a long time. Accordingly, the present invention provides a method to efficiently detect whether there is a one-bit error existing in the accessed data so as to solve the foresaid problem. Furthermore, the present invention can reduce the number of detecting components disposed on a circuit board of the host computer. Hence, the area of the circuit board occupied by the detecting components is reduced.